<?php
header("Content-Type: text/html;charset=utf-8");
include_once 'jdbc.php';
$name=$_POST['name'];
$sex=$_POST['sex'];
$age=$_POST['age'];
$dormitorynumber=$_POST['dormitorynumber'];
$college=$_POST['college'];
$profession=$_POST['profession'];
$class=$_POST['class'];
//返回的消息
$result=array();
if(trim($name)==""&&$name==null) {
    $result = array(
        "msg" => '名字不能为空',
        'code' => 0

    );
}
   else if(trim($sex)==""&&$sex==null) {
       $result = array(
           "msg" => '性别不能为空',
           'code' => 0

       );
   }
     else   if(trim($age)==""&&$age==null) {
         $result = array(
             "msg" => '年龄不能为空',
             'code' => 0

         );
     }
         else   if(trim($dormitorynumber)==""&&$dormitorynumber==null) {
             $result = array(
                 "msg" => '宿舍号不能为空',
                 'code' => 0

             );
         }
           else     if(trim($college)==""&&$college==null) {
               $result = array(
                   "msg" => '学院不能为空',
                   'code' => 0

               );
           }
               else     if(trim($profession)==""&&$profession==null) {
                   $result = array(
                       "msg" => '专业不能为空',
                       'code' => 0

                   );
               }
                   else     if(trim($class)==""&&$class==null) {
                       $result = array(
                           "msg" => '班级不能为空',
                           'code' => 0

                       );
                   }

               else{
                   $students=array(
                       'name'=>$name,
                       'sex'=>$sex,
                       'age'=>$age,
                       'dormitorynumber'=>$dormitorynumber,
                       'college'=>$college,
                       'profession'=>$profession,
                       'class'=>$class
                   );
                   $id=uniqid();//生成唯一ID
                   $sql="INSERT INTO students VALUES('$id','$name','$sex','$age','$dormitorynumber','$college','$profession','$class')";
                   $re = $conn->query($sql);
                   if($re==1){
                       $result = array(
                           "msg" => '添加成功',
                           'code' => 1

                       );
                   }
               }

echo json_encode($result,JSON_UNESCAPED_UNICODE);




